<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>

    (function (){
        function Observer(){
            this.obj = {};
            this.on = (type,handler) =>{
                this.obj[type] = this.obj[type] ? this.obj[type] : [];
                this.obj[type].push(handler);
            }
            this.emit = (type,amg) =>{
                if(this.obj[type]){
                    this.obj[type].forEach((item) => {
                        item(amg);
                    });
                }
            }
        }
        window.Observer = Observer;
    })()

    let oo = new Observer();

    oo.on('tangseng',function(amg){console.log('sunwukong 收到来自 tangseng 的消息:' + amg);});
    oo.on('tangseng',function(amg){console.log('zhubajie 收到来自 tangseng 的消息:' + amg);});

    oo.emit('tangseng','下周一出发取经');
    oo.emit('rulai','下周一出发取经');


</script>